package Io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Exercise2 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        FileOutputStream fos = new FileOutputStream("bj.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        osw.write("北京欢迎您...");
        osw.write("为你开天辟地");
        System.out.println("写出完毕!");
        osw.close();
        FileInputStream fis = new FileInputStream("bj.txt");
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        int d;
        while((d=isr.read())!=-1){
            System.out.print((char)d);
        }
        isr.close();

        /*
        FileOutputStream fos = new FileOutputStream("op.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        osw.write("给我翅膀，让我可以翱翔...");
        osw.write("给我力量，让我更坚强");
        System.out.println("写出完毕!");
        osw.close();
        FileInputStream fis = new FileInputStream("op.txt");
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        int d;
        while((d=isr.read())!=-1){
            System.out.print((char)d);
        }
        isr.close();



        FileInputStream fis = new FileInputStream("student.obj");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object obj = ois.readObject();
        Student zs = (Student)obj;
        System.out.println(zs);
        ois.close();

        FileInputStream fis2 = new FileInputStream("student.obj");
        ObjectInputStream ois2 = new ObjectInputStream(fis2);
        Object obj2 = ois2.readObject();
        Student ls = (Student)obj2;
        System.out.println(ls);
        ois.close();


        String name = "张三";
        int age =22;
        String gender = "男";
        String[] otherinfo={"是一名应届生","河南洛阳的","喜欢唱歌","喜欢王老师"};
        Student zs = new Student(name,age,gender,otherinfo);
        System.out.println(zs);
        FileOutputStream fos=new FileOutputStream("student.obj");
        ObjectOutputStream oos =new ObjectOutputStream(fos);
        oos.writeObject(zs);
        System.out.println("写出完毕");
        oos.close();


        String name = "李四";
        int age =25;
        String gender = "男";
        String[] otherinfo={"是一个研究生","河南驻马店的","喜欢科技知识","喜欢赵老师"};
        Student ls = new Student(name,age,gender,otherinfo);
        System.out.println(ls);
        FileOutputStream fos=new FileOutputStream("student.obj");
        ObjectOutputStream oos =new ObjectOutputStream(fos);
        oos.writeObject(ls);
        System.out.println("写出完毕");
        oos.close();
        */
    }
}